import { E_ItemGlobal } from "../defs/item/E_ItemGlobal";
import { E_PrayEffectType } from "../defs/lord/E_PrayEffectType";
import { CDItemGlobal } from "../excel/CDItemGlobal";
import { Player } from "../struct/Player";
import { SDHuangXiaoxi } from "./SDHuangXiaoxi";
import { SDPray } from "./SDPray";

/**
 * 数据-背包
 */
export abstract class SDBag {


    /**
     * 背包已满
     * @param player 
     * @returns 
     */
    public static isBagFull(player: Player): boolean {
        const rc = this.getBagResidualCapacity(player);
        return rc <= 0;
    }


    /**
    * 获取背包剩余容量
    * @param player 
    */
    public static getBagResidualCapacity(player: Player): number {
        const capacity = this.getBagCapacity(player);
        let cur = 0;
        if (player) {
            const ks = player.equipManager.getEquipKeys();
            const wearKs = player.equipManager.getWearKeys();
            cur = ks.length - wearKs.length;        //穿身上的不占用格子
        }
        return capacity - cur;
    }


    /**
     * 获取背包容量
     * @param player 
     * @returns 
     */
    public static getBagCapacity(player: Player): number {
        let v = 0;

        //初始容量
        {
            const basev = CDItemGlobal.getData(E_ItemGlobal.BagCell).value;
            v += basev;
        }

        //祝福增加的背包数量
        {
            const prayAdd = SDPray.getEffectByType(player, E_PrayEffectType.BagCapacity);
            v += Math.floor(prayAdd);
        }
        //黄小西增加的背包数量
        {
            const hxxAdd = SDHuangXiaoxi.getEffectByType(player, E_PrayEffectType.BagCapacity);
            v += Math.floor(hxxAdd);
        }
        return v;
    }


}
